package tacos.web.resources;

import lombok.Getter;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.RepresentationModel;
import org.springframework.hateoas.server.core.Relation;
import tacos.domain.Ingredient;
import tacos.domain.Taco;
import tacos.web.api.IngredientApiController;

import java.util.Date;
import java.util.List;

@Relation(value = "taco",collectionRelation = "tacos")  // 指定taco列表的单复数名称
public class TacoResource extends RepresentationModel<TacoResource> {
    /**
     * 相当于django中的serializer
     */
    private static final IngredientResourceAssembler ingredientAssembler = new IngredientResourceAssembler(IngredientApiController.class,IngredientResource.class);

    @Getter
    private final String name;

    @Getter
    private final Date createdAt;

    @Getter
    private final CollectionModel<IngredientResource> ingredients;

    public TacoResource(Taco taco){
        this.name = taco.getName();
        this.createdAt = taco.getCreatedAt();
        this.ingredients = ingredientAssembler.toCollectionModel(taco.getIngredients());
    }
}
